$.ajax({
    url:"{:url('admin/goods/getGoodsCate')}",
    data:{"type":"", "categroy":""},
    type:"post",
    dataType:"json",
    success:function (val) {
        var str=`<option value="" id="sectionclass">请选择一级分类</option>`;
        val=JSON.parse(val);

        for(var i=0;i<val.length;i++){
            var cur=val[i];
            str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
        }
        $("#first").html("");
        $("#first").html(str);
    }
});
$("#first").change(getsection);
$("#section").change(getthree);
function getsection() {
    var selectoption= $("#first option:selected");
    var id=selectoption.attr("name");
    $.ajax({
        url:"{:url('admin/goods/getGoodsCate')}",
        data:{"type":1, "categroy":id},
        type:"post",
        dataType:"json",
        async:false,
        success:function (val) {
            var str=`<option value="" id="sectionclass">请选择二级分类</option>`;
            val=JSON.parse(val);
            for(var i=0;i<val.length;i++){
                var cur=val[i];
                str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
            }
            $("#section").html("");
            $("#section").html(str);
        }
    })
}
function getthree() {
    var selectoption= $("#section option:selected");
    var id=selectoption.attr("name");
    $.ajax({
        url:"{:url('admin/goods/getGoodsCate')}",
        data:{"type":2, "categroy":id},
        type:"post",
        dataType:"json",
        async:false,
        success:function (val) {
            console.log(val);
            var str=`<option value="" id="threeclass">请选择三级分类</option>`;
            val=JSON.parse(val);

            for(var i=0;i<val.length;i++){
                var cur=val[i];
                str+=`<option name="${cur.id}"  value="${cur.categroy_name}">${cur.categroy_name}</option>`;
            }
            $("#three").html("");
            $("#three").html(str);
        }
    })
}
$("#three").change(function () {
    var $threeoption=$("#three option:selected");
    var id=$threeoption.attr("name");
    $("#threeid").val(id);
});